CMAKE_MINIMUM_REQUIRED( VERSION 2.8.8 )
PROJECT( OpenIG )

SET( OPENIG_VERSION 2.0.7 )
SET( OPENIG_MAJOR_VERSION 2 )
SET( OPENIG_MINOR_VERSION 0 )
SET( OPENIG_SUB_VERSION 7 )

SET( CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}" )

SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
IF( WIN32 )
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} )
    ADD_DEFINITIONS( -D_WIN32_WINNT=0x0501 )
ELSE()
    SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} )
ENDIF()

SET(DEF_INSTALL_CMAKE_DIR cmake)
SET(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")

IF( WIN32 AND MSVC )
    OPTION( OPENIG_WIN32_USE_MP "Build with multiple processes (/MP option; VS 2005 and above)." ON )
    MARK_AS_ADVANCED( OPENIG_WIN32_USE_MP )
    IF( OPENIG_WIN32_USE_MP )
        SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP" )
    ENDIF( OPENIG_WIN32_USE_MP )
ENDIF( WIN32 AND MSVC )

IF(CMAKE_COMPILER_IS_GNUCXX)
    INCLUDE(GNUInstallDirs)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

IF(NOT DEFINED CMAKE_INSTALL_LIBDIR)
    SET(CMAKE_INSTALL_LIBDIR lib)
ENDIF(NOT DEFINED CMAKE_INSTALL_LIBDIR)

IF(NOT "$ENV{OPENIG_BUILD}" STREQUAL "")
    SET(CMAKE_INSTALL_PREFIX "$ENV{OPENIG_BUILD}" CACHE PATH "OpeinIG install prefix" FORCE)
ENDIF()

INCLUDE( FindOSGHelper )
INCLUDE( FindBoostHelper )
INCLUDE( FindSilverLiningHelper )
INCLUDE( FindOsgEarthHelper )
INCLUDE( FindBulletHelper )
INCLUDE( FindOSGBullet )
INCLUDE( FindCstShare )
INCLUDE( FindMersive )
#INCLUDE( FindJRMSensors )
INCLUDE( FindCCL )

FIND_PACKAGE(OpenGL)
FIND_PACKAGE(Triton)
#To enable CUDA GPU culling, you must uncomment the next line
#and ensure that you have set the XML directive: "UseGPUAcceleration"
#to "yes" in your OpenIG openig.xml config/setup file.
#
#FIND_PACKAGE(CUDA)

#If you plan to use Intel TBB, set TBB_ROOT_DIR as appropriate
#FIND_PACKAGE(TBB)

INCLUDE_DIRECTORIES(
    ${PROJECT_SOURCE_DIR}
    ${OSG_INCLUDE_DIRS}
    ${PROJECT_SOURCE_DIR}/Core-Base
    ${PROJECT_SOURCE_DIR}/Core-PluginBase
    ${PROJECT_SOURCE_DIR}/Core-OpenIG
    ${PROJECT_SOURCE_DIR}/Core-Utils
)

ADD_SUBDIRECTORY( Core-Base )
ADD_SUBDIRECTORY( Core-PluginBase )
ADD_SUBDIRECTORY( Core-OpenIG )
ADD_SUBDIRECTORY( Core-Utils )

ADD_SUBDIRECTORY( Application-A320 )

ADD_SUBDIRECTORY( Utility-veggen )
ADD_SUBDIRECTORY( Utility-vegviewer )
ADD_SUBDIRECTORY( Utility-oigconv )

ADD_SUBDIRECTORY( Plugin-Animation )
ADD_SUBDIRECTORY( Plugin-GPUVegetation )
ADD_SUBDIRECTORY( Plugin-ForwardPlusLighting )
ADD_SUBDIRECTORY( Plugin-ModelComposition )
ADD_SUBDIRECTORY( Plugin-SkyDome )
ADD_SUBDIRECTORY( Plugin-VDBOffset )
ADD_SUBDIRECTORY( Plugin-FBXAnimation )
ADD_SUBDIRECTORY( Plugin-OSGParticleEffects )
ADD_SUBDIRECTORY( Plugin-LightsControl )
ADD_SUBDIRECTORY( Plugin-Networking )
ADD_SUBDIRECTORY( Plugin-SimpleLighting)

ADD_SUBDIRECTORY( Library-Graphics )
ADD_SUBDIRECTORY( Library-Networking )
ADD_SUBDIRECTORY( Library-Protocol )

IF( MERSIVE_FOUND )
 ADD_SUBDIRECTORY( Plugin-Mersive )
ENDIF( MERSIVE_FOUND )

IF( SILVERLINING_FOUND )
    ADD_SUBDIRECTORY( Plugin-SilverLining )
ENDIF( SILVERLINING_FOUND )

IF( TRITON_FOUND )
    ADD_SUBDIRECTORY( Plugin-Triton )
ENDIF( TRITON_FOUND )


#IF( JRMSENSORS_FOUND )
#    ADD_SUBDIRECTORY( Plugin-JRMSensors )
#ENDIF( JRMSENSORS_FOUND )

#IF( CSTSHARE_FOUND )
#    ADD_SUBDIRECTORY( Plugin-Muse )
#    ADD_SUBDIRECTORY( Plugin-OigWidget)
#ENDIF( CSTSHARE_FOUND )

IF( CCL_FOUND )
    ADD_SUBDIRECTORY( Plugin-CIGI )
ENDIF( CCL_FOUND )

IF( OSGEARTH_FOUND )
    INCLUDE_DIRECTORIES(
        ${OSGEARTH_INCLUDE_DIR}
    )
    ADD_SUBDIRECTORY( Application-Earth )
    ADD_SUBDIRECTORY( Plugin-OSGEarthSimpleLighting )
ENDIF( OSGEARTH_FOUND )

IF( BULLET_FOUND AND OSGBULLET_FOUND )
    ADD_SUBDIRECTORY( Library-Bullet )
    ADD_SUBDIRECTORY( Plugin-Bullet )
    ADD_SUBDIRECTORY( Application-Bullet)
ENDIF( BULLET_FOUND AND OSGBULLET_FOUND)

FIND_PATH(MYGUI_INCLUDE_DIR MYGUI/MyGUI.h)
FIND_LIBRARY(MYGUI_LIBRARY NAMES MyGUIEngine)
FIND_LIBRARY(MYGUI_OPENGL_LIBRARY NAMES MyGUI.OpenGLPlatform)

IF(MYGUI_INCLUDE_DIR AND MYGUI_LIBRARY)
    ADD_SUBDIRECTORY( Plugin-UI )
ENDIF(MYGUI_INCLUDE_DIR AND MYGUI_LIBRARY)

INSTALL(EXPORT openig-targets DESTINATION ${CMAKE_INSTALL_LIBDIR})

EXPORT(PACKAGE OpenIG)

#FILE(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")

CONFIGURE_FILE(OpenIGConfig.cmake.in "${PROJECT_BINARY_DIR}/OpenIGConfig.cmake" @ONLY)
SET(CONF_INCLUDE_DIRS "\${OPENIG_CMAKE_DIR}/${REL_INCLUDE_DIR}")

CONFIGURE_FILE(OpenIGConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenIGConfig.cmake" @ONLY)

CONFIGURE_FILE(OpenIGConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/OpenIGConfigVersion.cmake" @ONLY)


INSTALL(FILES
  "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenIGConfig.cmake"
  "${PROJECT_BINARY_DIR}/OpenIGConfigVersion.cmake"
  DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)

INSTALL(EXPORT openig-targets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)

CONFIGURE_FILE(
  "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  IMMEDIATE @ONLY)
IF( WIN32 )
  ADD_CUSTOM_TARGET(UNINSTALL
    "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
ELSE()
  ADD_CUSTOM_TARGET(uninstall
    "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
ENDIF()

